Skip to content

Add support for embedded _id in documentdb - #385

Merged
adiom-mark merged 1 commit into
mainfrom
docdbembedded
Jun 12, 2026
Merged

Add support for embedded _id in documentdb#385
adiom-mark merged 1 commit into
mainfrom
docdbembedded

Conversation

@adiom-mark

@adiom-mark adiom-mark commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes

    • Expanded document ID comparison to support many more BSON types (binary/UUID, boolean, datetime, timestamp, regex, JavaScript/code-with-scope, null/min/max keys, decimal128, nested documents/arrays).
    • Improved numeric ordering and handling of special values (NaN, ±Inf) and mixed numeric types.
    • More robust cross-type ordering and deterministic sorting for composite IDs.
  • Tests

    • Added extensive unit and integration tests validating comparator behavior and server-vs-local sort consistency.

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cc9ee34f-e982-4450-95e7-ad911adce3dd

📥 Commits

Reviewing files that changed from the base of the PR and between 61a1d7a and 29fa1f4.

📒 Files selected for processing (3)
  • connectors/mongo/docdb.go
  • connectors/mongo/docdb_sort_external_test.go
  • connectors/mongo/docdb_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • connectors/mongo/docdb_sort_external_test.go
  • connectors/mongo/docdb.go

📝 Walkthrough

Walkthrough

Overhauls BSON value comparison to a centralized, type-ordered comparator (handles numeric edge cases including Decimal128/NaN/±Inf, strings, binary, documents, arrays, timestamps, regex, JS code, null/min/max keys) and expands supported DocumentDB _id kinds; adds unit tests and an optional server integration test validating ordering.

Changes

BSON Comparison Infrastructure

Layer / File(s) Summary
Core BSON comparison implementation
connectors/mongo/docdb.go
compareBSONRawValues now uses a centralized bsonTypeSortOrder, delegates numeric comparison (including Decimal128, NaN, ±Inf) to new helpers, extracts strings/symbols correctly, and recursively compares documents/arrays. Imports math and math/big. supportedIDTypes updated to include additional BSON kinds.
Unit tests for BSON comparison
connectors/mongo/docdb_test.go
Adds unit tests validating supported embedded document _id types, deterministic sorting of composite/nested documents, mixed numeric ordering, handling of non-finite numbers, MongoDB-specific binary ordering (including UUID semantics), and field-type precedence before key/value comparison.
MongoDB server integration test
connectors/mongo/docdb_sort_external_test.go
Integration test (conditional on MONGO_SORT_TEST_URI) inserts documents with diverse _id edge cases and asserts the server _id sort order equals the local comparator order and that pairwise comparator signs agree.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • adiom-data/dsync#374: Both PRs modify DocumentDB _id sampling logic and the BSON comparison code paths used for sorting and sampling identifiers.

Poem

🐰 With twitching nose I hopped in place,

I matched each BSON in tidy space,
Decimals, NaN, and nested trees,
All lined up neat beneath my sneeze,
Hooray — the sort went at full pace!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes the main enhancement: adding support for embedded _id types in DocumentDB, which is confirmed by the substantial refactoring of BSON comparison logic, expanded supportedIDTypes map, and new test coverage for embedded document scenarios.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docdbembedded

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@connectors/mongo/docdb_sort_external_test.go`:
- Around line 31-33: The test currently always uses and drops the fixed
collection "dsync_sort_test.embedded_ids" (see
client.Database(...).Collection(...) and col.Drop(ctx)), which can cause
cross-run interference; change to derive the collection name from t.Name() plus
a unique suffix (e.g., a timestamp or random hex) and use that when calling
client.Database("dsync_sort_test").Collection(collName); assign the collection
to col and register a cleanup via t.Cleanup(func() { require.NoError(t,
col.Drop(ctx)) }) so the collection is removed after the test, and replace the
immediate require.NoError(t, col.Drop(ctx)) call with the cleanup to avoid
clobbering other runs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6ac0f91a-bd69-4c4e-9e89-0f209e2fe963

📥 Commits

Reviewing files that changed from the base of the PR and between 0ba7c4d and 61a1d7a.

📒 Files selected for processing (3)
  • connectors/mongo/docdb.go
  • connectors/mongo/docdb_sort_external_test.go
  • connectors/mongo/docdb_test.go

Comment thread connectors/mongo/docdb_sort_external_test.go Outdated
@adiom-mark
adiom-mark merged commit de58438 into main Jun 12, 2026
2 checks passed
@adiom-mark
adiom-mark deleted the docdbembedded branch June 12, 2026 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant